
package com.netease.xone.fragment;

import java.util.Calendar;

import com.netease.xone.R;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;
import android.widget.Toast;

public class FragmentDatePicker extends DialogFragment {

    public static final String TAG = "FragmentDatePicker";

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        // Create a new instance of DatePickerDialog and return it
        DatePickerDialog dialog = new DatePickerDialog(getActivity(), null, year, month, day);
        dialog.setTitle(R.string.birth);
        dialog.setCancelable(true);
        dialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.confirm),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = ((DatePickerDialog)dialog).getDatePicker();
                        Toast.makeText(
                                getActivity(),
                                "y:" + dp.getYear() + ",m:" + dp.getMonth() + ",d:"
                                        + dp.getDayOfMonth(), Toast.LENGTH_SHORT).show();
                    }
                });
        dialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.cancel),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        return dialog;
    }

}
